<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:include page="../comunes/header.jsp" />
<h2>Listado de &Oacute;rdenes de Trabajo</h2>
<button type="button" class="btn_agregar" title="Agregar" 
        onclick="window.location.href = '<c:url value="/ordenes?form"/>'">Crear una Orden</button>
<div class="wscroll" id="pnl_ordenes">
   <table class="tbl_listado">
      <thead>
         <tr>
            <th>N&deg;</th><th>Solicitante</th><th>Responsable</th><th>Zona</th>
            <th>Planta</th><th>Descripci&oacute;n</th><th>Fecha<br/>Inicio</th>
            <th>Fecha<br/>Fin</th><th>Tiempo<br/>de Resp.</th><th>Gener&oacute;<br/>Paro?</th>
            <th>Causa del Paro</th><th>Tiempo<br/>Paro</th>
            <th>N&deg; Equipos<br/>Mtto.</th><th>Estatus</th><th>Opc.</th>
         </tr>
      </thead>
      <tbody>
         <c:forEach var="orden" items="${ordenes}">
            <c:url var="editUrl" value="/ordenes/${orden.llave.numero}?serie=${orden.llave.serie}" />
            <c:url var="compUrl" value="/ordenes/comp?so=${orden.llave.serie}&no=${orden.llave.numero}" />
            <c:url var="pdfUrl" value="/ordenes/pdf?so=${orden.llave.serie}&no=${orden.llave.numero}" />
            <tr>
               <td><c:out value="${orden.llave.numero}"/></td>
               <td><c:out value="${orden.solicitante.nombre}"/></td>
               <td><c:out value="${orden.empleado.nombre} ${orden.empleado.apellidoPaterno}"/></td>
               <td><c:out value="${orden.zona.descripcion}"/></td>
               <td><c:out value="${orden.planta.descripcionCorta}"/></td>
               <td><textarea cols="25" rows="2" class="txa_descripcion" readonly="readonly">${orden.descripcion}</textarea></td>
               <td><fmt:formatDate pattern="dd/MM/yyyy" value="${orden.fechaInicio}" /></td>
               <td><fmt:formatDate pattern="dd/MM/yyyy" value="${orden.fechaFin}" /></td>
               <td>
                  <c:choose>
                     <c:when test="${orden.tiempoRespuesta > 0}">
                        <c:choose>
                           <c:when test="${orden.tiempoRespuesta > 60}">
                              <c:set var="minutosr" value="${orden.tiempoRespuesta%60}" />
                              <c:set var="horasr" value="${(orden.tiempoRespuesta-minutosr)/60}" />
                              <c:choose>
                                 <c:when test="${horasr > 24}">
                                    <c:set var="horas2r" value="${horasr%24}" />
                                    <c:set var="diasr" value="${(horasr-horas2r)/24}" />
                                    <fmt:formatNumber type="number" pattern="00" value="${diasr}" />dias,
                                    <fmt:formatNumber type="number" pattern="00" value="${horas2r}" />:<fmt:formatNumber type="number" pattern="00" value="${minutosr}" />
                                 </c:when>
                                 <c:otherwise>
                                    <fmt:formatNumber type="number" pattern="00" value="${horasr}" />:<fmt:formatNumber type="number" pattern="00" value="${minutosr}" />
                                 </c:otherwise>
                              </c:choose>
                           </c:when>
                           <c:otherwise>00:<c:out value="${orden.tiempoRespuesta}"/></c:otherwise>
                        </c:choose>
                     </c:when>
                     <c:otherwise>-</c:otherwise>
                  </c:choose>
               </td>
               <td>
                  <c:choose>
                     <c:when test="${orden.generoParo=='S'}">Si</c:when>
                     <c:when test="${orden.generoParo=='N'}">No</c:when>
                     <c:otherwise>N/A</c:otherwise>
                  </c:choose>
               </td>
               <td><textarea cols="18" rows="2" class="txa_descripcion" readonly="readonly">${orden.causaParo.descripcion}</textarea></td>
               <td>
                  <c:choose>
                     <c:when test="${orden.tiempoParo > 0}">
                        <c:choose>
                           <c:when test="${orden.tiempoParo > 60}">
                              <c:set var="minutos" value="${orden.tiempoParo%60}" />
                              <c:set var="horas" value="${(orden.tiempoParo-minutos)/60}" />
                              <c:choose>
                                 <c:when test="${horas > 24}">
                                    <c:set var="horas2" value="${horas%24}" />
                                    <c:set var="dias" value="${(horas-horas2)/24}" />
                                    <fmt:formatNumber type="number" pattern="00" value="${dias}" />dias,
                                    <fmt:formatNumber type="number" pattern="00" value="${horas2}" />:<fmt:formatNumber type="number" pattern="00" value="${minutos}" />
                                 </c:when>
                                 <c:otherwise>
                                    <fmt:formatNumber type="number" pattern="00" value="${horas}" />:<fmt:formatNumber type="number" pattern="00" value="${minutos}" />
                                 </c:otherwise>
                              </c:choose>
                           </c:when>
                           <c:otherwise>00:<c:out value="${orden.tiempoParo}"/></c:otherwise>
                        </c:choose>
                     </c:when>
                     <c:otherwise>-</c:otherwise>
                  </c:choose>
               </td>
               <td><c:out value="${orden.mantenimientos.size()}"/></td>
               <td>
                  <c:choose>
                     <c:when test="${orden.estatus=='A'}">Abierta</c:when>
                     <c:when test="${orden.estatus=='C'}">Complementada</c:when>
                     <c:when test="${orden.estatus=='P'}">En Pedido</c:when>
                     <c:when test="${orden.estatus=='F'}">Finalizada</c:when>
                     <c:when test="${orden.estatus=='X'}">Cancelada</c:when>
                     <c:otherwise>Otro...</c:otherwise>
                  </c:choose>
               </td>
               <td>
                  <button type="button" class="btn_pdf" title="Ver PDF" 
                          onclick="window.open('${pdfUrl}')">PDF</button>
                  <c:if test="${!(orden.estatus=='P' || orden.estatus=='F')}">
                     <button type="button" class="btn_editar" title="Editar" 
                             onclick="window.location.href = '${editUrl}&ac=e'">E</button>
                  </c:if>
                  <c:if test="${orden.estatus!='F'}">
                     <button type="button" class="btn_complementar" title="Complementar" 
                             onclick="window.location.href = '${compUrl}'">C</button>
                  </c:if>
               </td>
            </tr>
         </c:forEach>
      </tbody>
      <tfoot><tr><td colspan="14"></td><td><button type="reset" class="btn_regresar" title="Regresar">Regresar</button></td></tr></tfoot>
   </table>
</div><c:url var="regrUrl" value="/index" />
<script type='text/javascript'>
   $(document).ready(function() {
      $(".btn_regresar").click(function() {
         window.location.replace('${regrUrl}');
      });
   });
</script>
<jsp:include page="../comunes/footer.jsp" />